﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.BLL;
using KeRui.Common;
using System.Text;

public partial class Manage_Cms_NodeList : System.Web.UI.Page
{
    protected List<KeRui.Model.CmsNode> listCmsNode;
    private readonly string Act = ManageHelper.PageAct();
    protected int siteID = PageRequest.GetInt("siteID",-1);
    private KeRui.BLL.CmsNode bllCmsNode = new CmsNode();
    private bool flg = false;
    protected int play = -1;
    protected string PId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin();//登陆判断
        ManageHelper.CheckAdminPower("site_nodelist_" + siteID);//权限
        listCmsNode = bllCmsNode.GetListByPId(0, PageRequest.GetInt("siteid", -1));
        play = PageRequest.GetInt("play", -1);
        PId = ","+PageRequest.GetString("pnode")+",";
    }

    #region 列表显示

    protected string nodeList(int pNodeID,int siteID,int play)
    {
        List<KeRui.Model.CmsNode> list = bllCmsNode.GetListByPId(pNodeID, siteID);
        StringBuilder RetStr = new StringBuilder();
        foreach (KeRui.Model.CmsNode model in list)
        {
               RetStr.Append(
                    "<tr class=\"tdbg\" onmouseover=\"this.className='tdbg-dark';\" onmouseout=\"this.className='tdbg';\" >"+
                        "<td width=\"60%\">" + state(model, pNodeID, play) + "(<font style=\"color:blue\">"+model.NodeID + "</font>)</td>" +
                        "<td align=\"left\"  width=\"10%\">" + model.NodeKey + "</td>" +
                        "<td align=\"center\" style=\"width:30px;\"><a href=\"NodeItem.aspx?act=sort&f=-1&id=" + model.NodeID + "&siteId=" + model.SiteID + "\"><img src=\"../Pic/icon/up.gif\"   border=\"0\" alt=\"上升\" style=\"display:"+(pNodeID==0?"none":"")+"\"/></a></td>" +
                        "<td align=\"center\" style=\"width:30px;\"><a href=\"NodeItem.aspx?act=sort&f=1&id=" + model.NodeID + "&siteId=" + model.SiteID + "\"><img src=\"../Pic/icon/down.gif\" border=\"0\" alt=\"下降\" style=\"display:" + (pNodeID == 0 ? "none" : "") + "\"/></a></td>" +
                        "<td align=\"center\" style=\"width:80px;\"><a href=\"CommentList.aspx?siteID=" + siteID + "&nodeID=" + model.NodeID + "\">评论</a><span style=\"color: gray\">(0)</span></td>" +
                        "<td align=\"center\" style=\"width:120px;\"><a href=\"javascript:ymPrompt.win('NodeItem.aspx?siteid=" + siteID + "&nodeid=" + model.NodeID + "&act=edit',470,520,'编辑栏目',null,null,null,true);\">编辑</a>"+
                        " | <a href=\"NodeItem.aspx?act=del&id=" + model.NodeID + "&siteid=" + siteID + "\" onclick=\"javascript:return confirm('此操作将会删除栏目“" + model.NodeName + "”，确认吗？');\">删除</a>" +
                        " | <a href=\"javascript:ymPrompt.win('NodeItem.aspx?siteid=" + siteID + "&PID=" + model.NodeID + "',470,500,'添加',null,null,null,true);\">添加</a>" +
                        "</td>" +
                        //"<td align=\"center\" style=\"width:20px;\"><input type='checkbox' name='ChannelIDCollection' value='2' /></td>" +
                    "</tr>");
           if (model.ChildNum != 0)
           {
               string xs = "none";
               if (pNodeID == 0 || PId.IndexOf(","+model.NodeID+",") != -1)//||model.NodeID == 490 || model.NodeID == 434
               {
                   xs = "";
               }//(pNodeID == 0 || play == model.NodeID ? "" : "none")
               RetStr.Append("<tr id=\"tbl" + model.NodeID + "\" style=\"display:" + xs + "\"><td colspan=\"6\">");
               RetStr.Append("<table style=\"width:100%;\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" >");
               RetStr.Append(nodeList(model.NodeID, siteID, play));
               RetStr.Append("</table>");
               RetStr.Append("</td></tr>");
           }
        }
        return RetStr.ToString();
    }
    private string state(KeRui.Model.CmsNode model,int pNodeID,int play)
    {
        StringBuilder RetStr = new StringBuilder();
        if (model.ChildNum != 0)
        {
            RetStr.Append("<span style=\"width:" + (model.Depth *30 ) + "px;\">&nbsp;</span>");
        }
        else
        {
            RetStr.Append("<span style=\"width:" + (model.Depth * 30+16) + "px;\">&nbsp;</span>");
        }
        if (model.ChildNum != 0)
        {
            RetStr.Append("<img align=\"absmiddle\" style=\"cursor: pointer\" onclick=\"displayChildren('tbl" + model.NodeID + "',this);\" src=\"/Manage/Pic/tree/" + (pNodeID == 0 || play == model.NodeID ? "minus" : "plus") + ".gif\">");
        }
        RetStr.Append("<img align=\"absmiddle\" border=\"0\" src=\"/Manage/Pic/tree/folder.gif\" />");
        RetStr.Append(model.NodeName);
        //return "&nbsp;";
        return RetStr.ToString();
    }
   
    #endregion
}
